#include "request_param.hpp"
#include <string>
#include <json.hpp>
#include <utils/utils_string.hpp>

using namespace std;
using namespace bz;



void request_param::put(const std::string key, const std::string value)
{
#ifdef WIN32
	params[key] = utils_string::ascii_utf8(value);
#else
	params[key] == value;
#endif

}
void request_param::put(const std::string key, const char* value)
{
#ifdef WIN32
	params[key] = utils_string::ascii_utf8(value);
#else
	params[key] == value;
#endif
}
void request_param::put(const std::string key, bool value)
{
	params[key] = value ? "true" : "false";
}
void request_param::put(const std::string key, int value)
{
	params[key] = to_string(value);
}

std::string request_param::dump()
{
	string param_str;
	int index = 0;
	string cmp = "";
	for (auto it : params)
	{
		cmp = index ? "&" : "";
		param_str += cmp + it.first + "=" + it.second;
		++index;
	}
	return param_str;
}

string request_param::to_json()
{
	json out;
	for (auto it : params)
	{
		out[it.first] = it.second;

	}
	return out.dump();
}

int request_param::size()
{
	return params.size();
}
